package com.cool.controller.example;

import com.cool.model.common.ServerResponse;
import com.cool.service.example.TemplateServcie;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;


/**
 * 通用模板控制器
 * 这里以字典AdminDictionary为例
 */
@Controller
@RequestMapping("/template")
public class TemplateController {

    @Autowired
    private TemplateServcie templateServcie;


    /**
     * 详情
     * @param id
     * @return
     */
    @GetMapping(value = "/detail")
    @ResponseBody
    public ServerResponse detail(@RequestParam(value = "id",required = true) Long id){
        return templateServcie.detail(id);
    }


    /**
     * 列表
     * @return
     */
    @GetMapping(value = "/list")
    @ResponseBody
    public ServerResponse list(){
        return templateServcie.list();
    }


      /* 列表-分页
     * @param request
     * @param pageNumber 当前页
     * @param pageSize   每页显示记录数
     * @return
     */
    @GetMapping(value = "/pageList")
    @ResponseBody
    public ServerResponse pageList(@RequestParam(value = "pageNumber",required = false,defaultValue = "1") Integer pageNumber,
                                    @RequestParam(value = "pageSize",required = false,defaultValue = "10") Integer pageSize,
                                    HttpServletRequest request){
        return templateServcie.pageList(pageNumber,pageSize,request);
    }



    /**
     * 新增操作
     * @author yls
     * @param request
     * @param
     * @return
     */
    @PostMapping(value = "/save")
    @ResponseBody
    public ServerResponse save(AdminDictionary adminDictionary, HttpServletRequest request){
       return  templateServcie.save(adminDictionary,request);
    }





    /**
     * 更新操作
     * @author yls
     * @param request
     * @return
     */
    @PostMapping(value = "/update")
    @ResponseBody
    public ServerResponse  update(AdminDictionary adminDictionary, HttpServletRequest request){
        return  templateServcie.update(adminDictionary,request);
    }

    /**
     * 删除操作
     * @author yls
     * @return
     */
    @PostMapping(value = "/delete")
    @ResponseBody
    public ServerResponse deleteById(@RequestParam(value = "id",required = true) Long id){
        return  templateServcie.deleteById(id);
    }


}
